﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EvoSim.RandomNumberGenerators;
using EvoSim.Simulation.Creatures;
using TakaGUI;

namespace EvoSim.Simulation.Worlds
{
	public class FoodWorld : World
	{
		public int MinimumFood = 70;
		public int FoodSpawnRate = 1;
		int TimeUntilFoodSpawn = 0;

		public FoodWorld(int regionSize)
			: base(regionSize)
		{
		}

		public void CreateInitalFood()
		{
			for (int i = 0; i < MinimumFood; i++)
				CreateFood();
		}

		public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
		{
			base.Update(gameTime);

			int foodCount = 0;
			foreach (Entity entity in EntityList)
				if (entity.EntityName == "Food")
					foodCount += 1;

			if (foodCount < MinimumFood)
			{
				TimeUntilFoodSpawn -= 1;

				if (TimeUntilFoodSpawn < 0)
					TimeUntilFoodSpawn = FoodSpawnRate;

				if (TimeUntilFoodSpawn == 0)
				{
					CreateFood();
					TimeUntilFoodSpawn = 0;
				}
			}
		}

		void CreateFood()
		{
			Food food = new Food();
			AddEntity(food);

			food.Position = new EntityPosition(Globals.Random.Next(Width), Globals.Random.Next(Height));
		}
	}
}
